package cn.wolfcode.mp.service.impl;

import cn.wolfcode.mp.domain.Employee;
import cn.wolfcode.mp.mapper.EmployeeMapper;
import cn.wolfcode.mp.query.EmployeeQuery;
import cn.wolfcode.mp.service.IEmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

@Service
@Transactional
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public Page<Employee> queryPage(EmployeeQuery qo) {
        QueryWrapper<Employee> wrapper=new QueryWrapper<>();
        //分页逻辑
        Page<Employee> page=new Page<>(qo.getCurrentPage(),qo.getPageSize());
//        if (StringUtils.hasText(qo.getKeyWord())){
//            wrapper.like("name", qo.getKeyWord());
//        }
        //优雅:
        wrapper.like(StringUtils.hasText(qo.getKeyWord()), "name", qo.getKeyWord());
        return employeeMapper.selectPage(page, wrapper);
    }
}
